When reconstructing the color hash, try harder to avoid unnecessary
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 22 Aug 2008 03:51:56 +0000 (03:51 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 22 Aug 2008 03:51:56 +0000 (03:51 +0000)
        * gtk/gtksettings.c: When reconstructing the color hash, try
        harder to avoid unnecessary notification, since this can lead
        to infinite reloading of rc files in some situations.

svn path=/trunk/; revision=21182

ChangeLog
gtk/gtksettings.c

index 2013a35e53eb7ac440b373f923f11b6623e5e9ee..ddbc93adb13700294c823426dff0a1406bbeade7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-08-21  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtksettings.c: When reconstructing the color hash, try
+       harder to avoid unnecessary notification, since this can lead
+       to infinite reloading of rc files in some situations.
+
 2008-08-21  Cody Russell  <bratsche@gnome.org>
 
        * gdk/win32/gdkevents-win32.c (doesnt_want_key): Remove the checks
index 32e783944dc6c5dd9500c3286171373b81f39e28..1ec5ade207b300148caa60e888a7044aa8a86e20 100644 (file)
@@ -1892,14 +1892,13 @@ _gtk_settings_handle_event (GdkEventSetting *event)
       if (property_id == PROP_COLOR_SCHEME)
         {
           GValue value = { 0, };
-
           g_value_init (&value, G_TYPE_STRING);
           if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
             g_value_set_static_string (&value, "");
           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
           g_value_unset (&value);
         }
-
       g_object_notify (G_OBJECT (settings), pspec->name);
    }
 }
@@ -2258,6 +2257,7 @@ update_color_hash (ColorSchemeData   *data,
 {
   gboolean changed = FALSE;
   gint i;
+  GHashTable *old_hash;
 
   if ((str == NULL || *str == '\0') && 
       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
@@ -2291,8 +2291,7 @@ update_color_hash (ColorSchemeData   *data,
     return FALSE;
     
   /* Rebuild the merged hash table. */
-  if (data->color_hash)
-    g_hash_table_unref (data->color_hash);
+  old_hash = data->color_hash;
   data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
                                            (GDestroyNotify) gdk_color_free);
   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
@@ -2302,7 +2301,35 @@ update_color_hash (ColorSchemeData   *data,
                              data->color_hash);
     }
 
-  return TRUE;
+  if (old_hash)
+    {
+      /* now check if the merged hash has changed */
+      changed = FALSE;
+      if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
+        changed = TRUE;
+      else
+        {
+          GHashTableIter iter;
+          gpointer key, value, new_value;
+
+          g_hash_table_iter_init (&iter, old_hash);
+          while (g_hash_table_iter_next (&iter, &key, &value))
+            {
+              new_value = g_hash_table_lookup (data->color_hash, key);
+              if (!new_value || !gdk_color_equal (value, new_value))
+                {
+                  changed = TRUE;
+                  break;
+                } 
+            }
+        }
+
+      g_hash_table_unref (old_hash);
+    }
+  else 
+    changed = TRUE;
+
+  return changed;
 }
 
 static void